﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharepointSolutionInstaller.Views;
using Microsoft.SharePoint.Administration;
using System.Data.SqlClient;
using SharepointSolutionInstaller.Utils.Configuration;

namespace SharepointSolutionInstaller.Utils.SolutionDeployment
{
    /// <summary>
    /// The base class of all SharePoint solution related commands.
    /// </summary>
    public abstract class SolutionCommand : Command
    {
        protected SolutionCommand(InstallProcess parent) : base(parent) { }

        protected void RemoveSolution(Guid fileName)
        {
            try
            {
                SPFarm farm = SPFarm.Local;
                SPSolution solution = farm.Solutions[fileName];
                if (solution != null)
                {
                    if (!solution.Deployed)
                    {
                        solution.Delete();
                    }
                }
            }

            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
    }
}
